﻿
function createGrid(objArray,path) {
	var str="";
	
	
	try{
	    var array = typeof objArray != 'object' ? JSON.parse(objArray) : objArray;
	    str+='<a onclick="addFolder(\''+path+'\')" href="#">新建文件夹</a>|\
			  <a href="#" onclick="upload();">上传资源</a>|';
	    str+='<a class="dash_btn" onclick="dash(\''+path+'\')" href="#">回收站</a>';
	    if(path!='a-1'){
	    	var path1=path.substring(0,path.lastIndexOf('a'));
	    	str+='|<a href="#" onclick="request(\'a-1\')">资源首页</a>|\
	    	 <a href="#" onclick="request(\''+path1+'\')">返回上一级</a>';  
	    }
	    
	    str+='<br/>';
	    str+='<table class="grid"><tbody><tr>';
	    for (var i = 0; i < array.length; i++) {
	    	var item=array[i];
	    	if(item.type==4){
	    		str+='<td align="center">\
	    			<p><a class="pic" href="#" onclick="request(\''+path+'a'+item.rid+'\')">\
					<img id="img_type" src="../../static/img/file_type/folder.png"  >\
					</a></p>\
					<p id="'+item.rid+'_name"> '+item.name+'</p>\
					<p id="foper" style="overflow:hidden;">\
					<a href="#" onclick="rename1(\''+item.rid+'\',\''+item.pid+'\')">重命名</a>|\
					<a href="#" onclick="del(\''+item.rid+'\',\''+item.type+'\',\''+item.path+'\')">删除</a>';
			
	    	}else{
	    		str+='<td>\
					<a class="pic" href="/resource/resource_show.do?rid='+item.rid+'" onclick="show_resource(\''+item.rid+'\')">\
					<img id="img_type" src="'+getPicPath(item.orgi_file_name)+'"  >\
					</a>\
					<p id="'+item.rid+'_name"> '+item.name+'</p>\
					<p >\
					<a href="#" onclick="show_resource(\''+item.rid+'\')">详细</a>|\
					<a href="#" onclick="show_resource(\''+item.rid+'\')">下载</a>|\
					<a href="#" onclick="show_resource_online(\''+item.rid+'\')">在线预览</a></p>\
				</td>';
	    	}
	    	if((i+1)%4==0){
	    		str+='</tr><tr>';
	    	}
	    }
	
		str+='</tr></tbody></table>';
	}catch(error){
		alert(error);
	}
    return str;
}

function getPicPath(orgi_file_name){
	var picPath=["word","excel","ppt","pdf","text","other"];
	var ext=orgi_file_name.substring(orgi_file_name.lastIndexOf(".")+1);
	var p=5;
	if(ext=="doc"||ext=="docx"){
		p=0;
	}else if(ext=="xls"||ext=="xlsx"){
		p=1;
	}else if(ext=="ppt"||ext=="pptx"){
		p=2;
	}else if(ext=="pdf"){
		p=3;
	}else if(ext=="txt"){
		p=4;
	}else{
		p=5;
	}
	return "../../static/img/file_type/"+picPath[p]+".png";
}





